<?php

namespace App\Kuafu\Coupon\Validate;

use App\Kuafu\Coupon\Enum\CouponEnum;
use Illuminate\Http\Request;
use App\Kuafu\Base\Validate\BaseValidate;

class CouponValidate extends BaseValidate
{
    public static function getCouponById($data)
    {
        $rules    = [
            'id' => 'required|integer|min:0',
        ];
        $messages = [];

        return self::validateCheck($data, $rules, $messages);
    }

    public static function getCouponList($data)
    {
        $rules    = [
            'pageSize' => 'required|integer|min:0',
            'pageNum'  => self::commonRules('pageNum'),
        ];
        $messages = [];

        return self::validateCheck($data, $rules, $messages);
    }


    public static function addCoupon($data)
    {
        $rules    = [
            'type'                => 'required|int|in:' . implode(',', array_keys(CouponEnum::COUPONTYPE)),
            'name'                => 'required|string|min:1|max:50',
            'useTimeType'         => 'required|int|in:' . implode(',', array_keys(CouponEnum::TIME_TYPES)),
            'discount'            => 'required|int|min:0',
            'startAt'             => 'required',
            'endAt'               => 'required',
            'useCondition'        => 'required|int|min:0',
            "availableSource"     => "required|array",
            "availableSource.*"   => "int|min:0",
            'isSuperposeCoupon'   => 'required_if:type,' . CouponEnum::COUPON_TYPE_VOUCHERS . ',' . CouponEnum::COUPON_TYPE_DISCOUNT . '|int|in:0,1',
            'isSuperposeActivity' => 'required_if:type,' . CouponEnum::COUPON_TYPE_VOUCHERS . ',' . CouponEnum::COUPON_TYPE_DISCOUNT . '|int|in:0,1',
            "unableDate"          => "sometimes|array",
            "unableDate.*"        => "int|min:1|max:8",
            'unableTime'          => 'sometimes|array',
            'canUseProduct'       => 'exclude_unless:type,' . CouponEnum::COUPON_TYPE_EXCHANGE . '|int|min:1',
            'couponImg'           => 'required_if:type,' . CouponEnum::COUPON_TYPE_EXCHANGE . '|string|min:1|max:255',
//            'productId'           => 'required_if:type,2|int',
        ];
        $messages = [];

        return self::validateCheck($data, $rules, $messages);
    }

    public static function setCoupon($data)
    {
        $rules    = [
            'id' => 'required|integer|min:0',
        ];
        $messages = [];

        return self::validateCheck($data, $rules, $messages);
    }

    public static function delCoupon($data)
    {
        $rules    = [
            'id' => 'required|integer|min:0',
        ];
        $messages = [];

        return self::validateCheck($data, $rules, $messages);
    }

    public static function patchCouponStatus($data)
    {
        $rules    = [
            'id'     => 'required|integer|min:0',
            'status' => 'required|integer|between:0,1,2',
        ];
        $messages = [];

        return self::validateCheck($data, $rules, $messages);
    }

    public static function getCouponRelease($data)
    {
        $rules    = [
            'couponId' => 'required|integer|min:0'
        ];
        $messages = [];

        return self::validateCheck($data, $rules, $messages);
    }
}
